#include "gofgame/jumpdown/sprite/ResilientPedal.h"
#include "gofgame/jumpdown/util/AnimateBuilder.h"
#include "gofgame/jumpdown/util/objective-c.h"
#include "SimpleAudioEngine.h"

using namespace gofgame::jumpdown::sprite;
using namespace gofgame::jumpdown::util;
using namespace CocosDenshion;

bool ResilientPedal::init() {
	if (!Pedal::initWithSpriteFrameName("tang2.png")) {
		delete this;
		return false;
	}
	initAnimate();
	this->setFlipY(true);
	return true;
}

void ResilientPedal::initAnimate(){
	this->resilientAnnmate = 
		AnimateBuilder("JumpDown.plist")
		.add("tang.png")
		.add("tang2.png")
		.add("tang3.png")
		.add("tang2.png")
		.buildAnimate(0.1F);
}

void ResilientPedal::playResilient() {
	this->stopAction(this->resilientAnnmate);
	this->runAction(this->resilientAnnmate);
}

ResilientPedal::~ResilientPedal() {
}


ResilientPedal *ResilientPedal::createResilientPedal(){
	ResilientPedal *resilientPedal;
	if (oc_new<ResilientPedal>(&resilientPedal)) {
		resilientPedal->autorelease();
	}
	return resilientPedal;
}

bool ResilientPedal::onTouchHero(Hero* hero){
	SimpleAudioEngine::sharedEngine()->playEffect("g2spring.wav");
	this->playResilient();
	hero->recoverHp();
	hero->setDropSpeed(4 * hero->getDropSpeed());
	return false;
}
